package com.sq.shortlink.project.controller;

import com.sq.shortlink.project.common.convension.result.Result;
import com.sq.shortlink.project.common.convension.result.Results;
import com.sq.shortlink.project.service.UrlTitleService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 短链接标题控制器
 * @author quan
 */
@RestController
@RequiredArgsConstructor
public class UrlTitleController {
    private final UrlTitleService urlTitleService;

    /**
     * 根据网站链接获取对应的网站标题
     * @param url 网站链接
     * @return 网站标题
     */
    @GetMapping("/api/short-link/v1/title")
    public Result<String> getTitleByUrl(@RequestParam("url") String url){
        return Results.success(urlTitleService.getTitleByUrl(url));
    }
}
